<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Supplier Stock Summery" >
                        <h:panelGrid columns="2" >
                            <h:outputLabel value="Department" ></h:outputLabel>
                            <p:autoComplete completeMethod="#{departmentController.completeDept}" 
                                            var="dept" itemLabel="#{dept.name}" itemValue="#{dept}" 
                                            forceSelection="true" value="#{reportsStock.department}" converter="departmentConverter" >
                            </p:autoComplete>
                        </h:panelGrid>
                        <h:panelGrid columns="3" >
                            <p:commandButton ajax="false" value="Process" 
                                            actionListener="#{reportsStock.fillAllDistributorStocks()}" ></p:commandButton>
                            <p:commandButton value="Print" ajax="false" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                <pe:exporter type="xlsx" target="tbl" fileName="Category_report"  />
                            </p:commandButton>
                        </h:panelGrid>

                        <h:panelGroup id="gpBillPreview">
                            <p:dataTable id="tbl" value="#{reportsStock.records}" var="i"
                                         rowIndexVar="ii"
                                         rows="20"
                                         paginator="true"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="20, 50, 100" 
                                         >
                                <f:facet name="header">
                                    <h:outputLabel value="Supplier Stock Summery - #{reportsStock.department.name}"/>  
                                </f:facet>
                                <p:column headerText="No." style="width: 40px;">

                                    <h:outputLabel value="#{ii+1}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Supplier" 
                                          sortBy="#{i.institution.name}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Supplier"/>
                                    </f:facet>
                                    <p:commandLink value="#{i.institution.name}"
                                                  action="#{reportsStock.fillDistributorStocks()}" ajax="false" >
                                        <f:setPropertyActionListener target="#{reportsStock.institution}"
                                                                     value="#{i.institution}"/>
                                    </p:commandLink>
                                </p:column>
                                <p:column headerText="Stock" 
                                          sortBy="#{i.qty}"
                                          styleClass="averageNumericColumn">
                                    <f:facet name="header">
                                        <h:outputLabel value="Stock"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.qty}"  >
                                        <f:convertNumber pattern="#,###" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Purchase Value" 
                                          styleClass="averageNumericColumn"
                                          style="text-align: right;"
                                          sortBy="#{i.purchaseValue}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Purchase Value"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.purchaseValue}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                    <f:facet name="footer" >
                                        <h:outputLabel value="#{reportsStock.stockPurchaseValue}" >
                                            <f:convertNumber parent="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                                <p:column headerText="Sale Value"
                                          styleClass="averageNumericColumn"
                                          style="text-align: right;"
                                          sortBy="#{i.retailsaleValue}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Sale Value"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.retailsaleValue}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                    <f:facet name="footer" >
                                        <h:outputLabel value="#{reportsStock.stockSaleValue}" >
                                            <f:convertNumber parent="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>



                                <p:columnGroup type="footer">
                                    <p:row>
                                        <p:column colspan="3" footerText="Total">
                                            <f:facet name="footer">
                                                <h:outputLabel value="Total" />
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" footerText="#{reportsStock.stockPurchaseValue}">
                                            <f:facet name="footer" >
                                                <h:outputLabel value="#{reportsStock.stockPurchaseValue}" >
                                                    <f:convertNumber parent="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" footerText="#{reportsStock.stockSaleValue}">
                                            <f:facet name="footer" >
                                                <h:outputLabel value="#{reportsStock.stockSaleValue}" >
                                                    <f:convertNumber parent="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                    </p:row>
                                    <p:row>
                                        <p:column colspan="5" >
                                            <f:facet name="footer" >
                                                <h:outputLabel value="Printed At " ></h:outputLabel>
                                                <h:outputLabel value="#{sessionController.currentDate}" >
                                                    <f:convertDateTime pattern="dd MMMM yyyy - hh:mm a" ></f:convertDateTime>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                    </p:row>
                                </p:columnGroup>
                            </p:dataTable>
                        </h:panelGroup>
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>
    </h:body>
</html>
